﻿using System;
using System.IO;

namespace Vosc.VirtualOscilloscope
{
	// Token: 0x0200001E RID: 30
	internal class TestDataGenerator
	{
		// Token: 0x060000C3 RID: 195 RVA: 0x0000CC5A File Offset: 0x0000AE5A
		private TestDataGenerator()
		{
		}

		// Token: 0x060000C4 RID: 196 RVA: 0x0000CC64 File Offset: 0x0000AE64
		public static void GenerateSineCurve(string resultFile, int curveFrenquency, int sampleFrenquency, double curveStartRadian, double dataAmpFactor, int totalSeconds)
		{
			if (sampleFrenquency % curveFrenquency != 0)
			{
				throw new ArgumentException();
			}
			if (sampleFrenquency > 65535)
			{
				throw new ArgumentException();
			}
			if (File.Exists(resultFile))
			{
				File.Delete(resultFile);
			}
			int num = sampleFrenquency / curveFrenquency;
			double num2 = 6.2831853071795862 / (double)num;
			int num3 = totalSeconds * sampleFrenquency;
			bool flag = true;
			double num4 = curveStartRadian;
			using (FileStream fileStream = File.Create(resultFile))
			{
				fileStream.WriteByte((byte)(sampleFrenquency >> 8 & 255));
				fileStream.WriteByte((byte)(sampleFrenquency & 255));
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(2);
				for (int i = 0; i < num3; i++)
				{
					int num5 = (int)((Math.Sin(num4) + 1.0) * 0.5 * dataAmpFactor);
					num5 -= (int)(dataAmpFactor / 2.0);
					num4 += num2;
					fileStream.WriteByte((byte)(num5 >> 8 & 255));
					fileStream.WriteByte((byte)(num5 & 255));
					fileStream.WriteByte((byte)(flag ? 1 : 0));
				}
			}
		}

		// Token: 0x060000C5 RID: 197 RVA: 0x0000CD90 File Offset: 0x0000AF90
		public static void GenerateSingleDigitalCurve(string resultFile, int curveFrenquency, int sampleFrenquency, int totalSeconds)
		{
			if (sampleFrenquency % curveFrenquency != 0)
			{
				throw new ArgumentException();
			}
			if (sampleFrenquency > 65535)
			{
				throw new ArgumentException();
			}
			if (File.Exists(resultFile))
			{
				File.Delete(resultFile);
			}
			Random random = new Random();
			int num = totalSeconds * sampleFrenquency;
			bool flag = true;
			bool flag2 = true;
			using (FileStream fileStream = File.Create(resultFile))
			{
				fileStream.WriteByte((byte)(sampleFrenquency >> 8 & 255));
				fileStream.WriteByte((byte)(sampleFrenquency & 255));
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				for (int i = 0; i < num; i++)
				{
					if (random.Next(1000) < 10)
					{
						flag2 = !flag2;
					}
					int num2 = flag2 ? 1 : 0;
					fileStream.WriteByte((byte)(num2 >> 8 & 255));
					fileStream.WriteByte((byte)(num2 & 255));
					fileStream.WriteByte((byte)(flag ? 1 : 0));
				}
			}
		}

		// Token: 0x060000C6 RID: 198 RVA: 0x0000CE98 File Offset: 0x0000B098
		public static void GenerateMultipleDigitalCurve(string resultFile, int curveFrenquency, int sampleFrenquency, int totalSeconds)
		{
			if (sampleFrenquency % curveFrenquency != 0)
			{
				throw new ArgumentException();
			}
			if (sampleFrenquency > 65535)
			{
				throw new ArgumentException();
			}
			if (File.Exists(resultFile))
			{
				File.Delete(resultFile);
			}
			Random random = new Random();
			int num = totalSeconds * sampleFrenquency;
			bool flag = true;
			bool flag2 = true;
			using (FileStream fileStream = File.Create(resultFile))
			{
				fileStream.WriteByte((byte)(sampleFrenquency >> 8 & 255));
				fileStream.WriteByte((byte)(sampleFrenquency & 255));
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(0);
				fileStream.WriteByte(1);
				for (int i = 0; i < num; i++)
				{
					if (random.Next(1000) < 10)
					{
						flag2 = !flag2;
					}
					int num2 = flag2 ? 65535 : 0;
					fileStream.WriteByte((byte)(num2 >> 8 & 255));
					fileStream.WriteByte((byte)(num2 & 255));
					fileStream.WriteByte((byte)(flag ? 1 : 0));
				}
			}
		}
	}
}
